#include "DemoWnd.h"

class CTest : public CWinWnd
{
public:
	CTest(HWND hWnd) 
	{
		Create(_T("test"), WS_POPUPWINDOW|WS_TILEDWINDOW, 0, 0, 400, 280, hWnd);
	}

	DWORD GetClassStyle() const
	{
		return CS_VREDRAW|CS_HREDRAW;
	}

	const TCHAR* GetClassName() const
	{
		return _T("_Win321");
	}

	LRESULT WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
	{
		switch (nMsg)
		{
			case WM_CREATE:
			{
				CenterWindow();
				break;
			}
			case WM_LBUTTONDOWN:
			{
				
				break;
			}
			case WM_DESTROY:
			{	
				DestroyWindow();
				
				break;
			}
		}
		return CWinWnd::FinalWndProc(hWnd, nMsg, wParam, lParam);
	}
};

CDemoWnd::CDemoWnd(void) : test(NULL)
{
	Create(_T("DemoApp"), WS_OVERLAPPEDWINDOW, 0, 0, 800, 480, NULL);
}

CDemoWnd::~CDemoWnd(void)
{
	delete test;
}

const TCHAR* CDemoWnd::GetClassName() const
{
	return _T("_Win32");
}

LRESULT CDemoWnd::WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	switch (nMsg)
	{
		case WM_CREATE:
		{
			CenterWindow();
			break;
		}
		case WM_LBUTTONDOWN:
		{
			if (NULL != test)
			{
				test->DestroyWindow();
				delete test;
				test = NULL;
			}

			test = new CTest(m_hWnd);
			test->ShowWindow(SW_SHOW);
			
			break;
		}
		case WM_DESTROY:
		{
			PostQuitMessage(0);
			break;
		}
	}

	return __super::FinalWndProc(hWnd, nMsg, wParam, lParam);
}